<cfsilent>
	<cfscript>
		questionID = Event.getValue("questionID");
		question = Event.getValue("question");
		stAnswers = Event.getValue("stAnswers");
	</cfscript>
</cfsilent>
<cfoutput>
	<script language="javascript">
		var numQuestion = 4;
		function addMoreQuestion(){
			numQuestion++;
			answerHTML = "<input type='text' name='answer" + numQuestion +"' text=''>";
			answerHTML = answerHTML + "<input type='checbox' name='isTrue" + numQuestion + "'><br />";
			
			$("##answerHolder").append( answerHTML );
		}
		
		function saveQuestion(){
			var question = $("[ name = question ]").val();
			var action = $("[ name = questionAction ]").val();
			//alert( action );
			var theURL = "?";
			//alert( $("[ class = isCorrect :checked ]").val() );
			for ( var i = 1; i <= numQuestion; i++ ){
				//alert( "answer "+i+" "+ $("[ name = isCorrect"+i+"]" ).attr("checked") );
				
				theURL = theURL + "answer" + i + "=" + $("[ name = 'answer"+i+"']").val() + "&"; 
				theURL = theURL + "isCorrect" + i + "=" + $("[ name = 'isCorrect"+i+"']").attr("checked") + "&";
				theURL = theURL + "answerID" + i + "=" + $("[ name = 'answerID"+i+"']").val() + "&";
			}
			theURL = theURL + "question=" + question + "&action=" + action;
			
			//pass to Ajax
			//alert( theURL );
		}
	</script>
	<h2>Add/Edit Exam Question</h2>
	<form action="/index.cfm" method="post">
		<input type="hidden" name="questionID" value="#questionID#">
		<input type="hidden" name="event" value="admin.doSaveExamQuestion">
		<label><strong>Question:</strong></label>		
		<input type="text" name="question" value="#question#" style="width:400px"><br /><br />
		
		<cfif NOT StructIsEmpty( stAnswers )>
			<input type="hidden" name="action" value="edit"><!--- indicates adding question --->
		
		<cfelse>
			<div id="answerHolder">
			<input type="hidden" name="questionAction" value="add"><!--- indicates adding question --->
			<cfloop from="1" to="4" index="i">
				<label>Answer #i# : <input type="text" name="answer#i#" value="" style="width:300px"></label>
				<label><input type="checkbox" name="isCorrect#i#" class="isCorrect" value="#i#"></label>
				<input type="hidden" name="answerID#i#" value="0">
				<br />
			</cfloop>
			</div>
			<input type="button" value="Add more question" onclick="javascript:addMoreQuestion()">
		</cfif>
		<!--- <cfdump var="#stAnswers#"> --->	
<!--- 		<cfloop collection="stAnswers" item="answerID">
			<cfset oAnswer = StructFind( stAnswers, answerID )>
			Answer: <input type="text" name="answer" value="#oAnswer.getAnswer()#">|
			Correct answer? <input type="radio" name="is_correct" value="no">No
			<input type="radio" name="is_correct" value="yes">YUes
			<br/>
			
		</cfloop>
 --->		<input type="button" name="submit" value="Save question" onclick="saveQuestion()">
	</form>
</cfoutput>